package com.ruoyi.web.controller.news.api;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.news.NewsRelatedDownload;
import com.ruoyi.system.domain.news.query.NewsRelatedDownloadQuery;
import com.ruoyi.system.domain.news.vo.NewsRelatedDownloadVo;
import com.ruoyi.system.service.news.NewsRelatedDownloadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/news/newsRelatedDownload")
@Api(value = "newsRelatedDownloadApiController", tags  = "测评工具下载Api")
public class NewsRelatedDownloadApiController extends BaseController {

	@Resource
	private NewsRelatedDownloadService newsRelatedDownloadService;

	@ApiOperation(value = "获取单个测评工具下载信息", notes = "获取单个测评工具下载信息")
	@GetMapping("/getById")
	public R<NewsRelatedDownload> getById(@RequestParam(value = "id") Long id) {
		NewsRelatedDownloadQuery newsRelatedDownloadQuery = new NewsRelatedDownloadQuery();
		newsRelatedDownloadQuery.setId(id);
		List<NewsRelatedDownloadVo> newsRelatedDownloadList = newsRelatedDownloadService.getNewsRelatedDownloadList(newsRelatedDownloadQuery);
		if (newsRelatedDownloadList!=null&&newsRelatedDownloadList.size()>0) {
			return R.ok(newsRelatedDownloadList.get(0));
		} else {
			return R.fail("数据不存在");
		}
	}

	@ApiOperation(value = "获取测评工具下载信息列表")
	@PostMapping(value = "/list")
	public R<PageInfo<NewsRelatedDownloadVo>> list(@RequestBody NewsRelatedDownloadQuery newsRelatedDownloadQuery) {
        newsRelatedDownloadQuery.setIsEnable("1");
		List<NewsRelatedDownloadVo> newsRelatedDownloadList = newsRelatedDownloadService.getNewsRelatedDownloadList(newsRelatedDownloadQuery);
		return R.ok(new PageInfo<>(newsRelatedDownloadList));
	}
}
